package com.ruoyi.business.service.impl.quickrepay;


import com.ruoyi.bizsys.domain.LoanIou;
import com.ruoyi.bizsys.domain.ReduceConfig;
import com.ruoyi.business.Vo.CustReduceRes;
import com.ruoyi.business.service.CustReduceProess;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author wqg
 * @description 剩余本金是否大于配置表的设置应还本金下限repaymentAmtMin
 * @date 2022/4/7
 */
@Slf4j
@Order(2)
@Component
public class ReduceResidueRrincipalImpl implements CustReduceProess {
    @Override
    public CustReduceRes handle(ReduceConfig reduceConfig, LoanIou loanIou, CustReduceRes custReduceRes) {
        //等于0，则b1=b2；
        //等于 1 ，则b1>b2 ;
        //等于-1，则b1<b2。
        // 剩余本金
        BigDecimal subAmt =  loanIou.getLoanPrincipal().subtract(loanIou.getRepaidPrincipal());
        if(subAmt.compareTo(reduceConfig.getRepaymentAmtMin())<=0){
            log.info("CustReduceProess:{}剩余本金{}小于配置本金下限{}",loanIou.getCustNo(),subAmt,reduceConfig.getRepaymentAmtMin());
            custReduceRes.setIsHave(false);
            return custReduceRes;
        }
        return custReduceRes;
    }
}
